package com.example.recyclerviewdemo;

import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.os.Bundle;
import android.widget.LinearLayout;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        intiView();
    }

    private void intiView() {
        RecyclerView recyclerView = findViewById(R.id.recycler_view);
        LinearLayoutManager llm=new LinearLayoutManager(this);
        //LinearLayoutManager默认情况下是垂直VERTICAL
        //水平显示
       //llm.setOrientation(LinearLayoutManager.HORIZONTAL);
        //llm.setOrientation(LinearLayoutManager.VERTICAL);

        //GridView
        //网格模式，默认垂直，给定默认为列
        //网格模式。设置水平后，原本的列数变为行数，水平滚动
        //参数4  排列上下反转
        //根据屏幕宽度自动调节列数
       GridLayoutManager glm=new GridLayoutManager(this,4,GridLayoutManager.VERTICAL,false);
        //RecyclerView一开始必须给定列表样式，否则无法显示
        recyclerView.setLayoutManager(llm);
        List<ContactModel> list=new ArrayList<>();
        for (int i=0;i<20;i++){
            ContactModel model=new ContactModel();
            model.setContactName("张三"+i);
            model.setContactIconTd(R.mipmap.ic_launcher);
            list.add(model);
        }
        MyAdapter adapter=new MyAdapter(this);
        adapter.setDataList(list);
        recyclerView.setAdapter(adapter);


    }
}